//
//  xianhuoDatailView.m
//  YaoHeAPP
//
//  Created by xyh on 16/1/26.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "xianhuoDatailView.h"
#import "Masonry.h"
#import "TongYong.h"
#import "Define.h"
#import "AccurateVC.h"
#import "UILabel+StringFrame.h"
#import "gouwuCarVC.h"
#import "Controller.h"
#import "SureOrderVC.h"
#import "gouwucartModel.h"
#import "zijinzhanghuVC.h"
#import "CreateCompanyVC.h"
#import "NSString+formatWithFloat.h"
#import "FindCompanyViewController.h"
#import "CompanyInviteCodeViewController.h"
#import "YongHuQuanXuanModel.h"
#import "MJExtension.h"

#define bgVCcolor [UIColor colorWithRed:235.f/255.f green:235.f/255.f blue:244.f/255.f alpha:1]
#define Color153  [UIColor colorWithRed:80.f/255.f green:80.f/255.f blue:80.f/255.f alpha:1]
#define kAlphaNum @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

@interface xianhuoDatailView ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>
{
    UITableView*_tableView;
    NSMutableArray*_detailArray;//存放详情
        
    NSArray*arrayT;
    
    UITextField *zhongliang;
    
    NSInteger weighttext;
    
    UILabel*danwei;
    
    UIButton *Addbut;//加号
    
    UIButton *Redbut;//减号
    
    UIButton *addshop;
    UIButton *buybut;
    
    NSString *iphoneNum;
    
    UIView *_titleView;
    
    
}

@property (nonatomic, strong) UILabel *danjiaLabel;                         // 单价label
@property (nonatomic, strong) UILabel *hejiLabel;
@property (nonatomic, strong) YongHuQuanXuanModel *yongHuQuanXuanModel;// 合计label

@end

@implementation xianhuoDatailView

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"xianhuoDatailView"];
    
     [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    
    //判断权限
    [self panduanCreate];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"xianhuoDatailView"];
    
     [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden=YES;
    
    self.view.backgroundColor=bgVCcolor;
    //加一个导航条
    UIView*navcBar=[[UIView alloc]init];
    navcBar.backgroundColor=[UIColor colorWithRed:90.f/255.f green:191.f/255.f blue:219.f/255.f alpha:1];
    [self.view addSubview:navcBar];
    [self.view bringSubviewToFront:navcBar];
    [navcBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);   make.left.offset(0);
        make.height.offset(kNavigationBarHeight);  make.right.offset(0);
    }];
    //导航条标题
    UILabel*titleLabel=[[UILabel alloc]init];
    titleLabel.text=@"货品详情";
    titleLabel.font=Font(17);
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.textColor=[UIColor whiteColor];
    [navcBar addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25);
        make.left.offset(self.view.frame.size.width/2-70);
        make.width.offset(140);
        make.height.offset(30);
    }];
    
    //返回按钮
    UIButton*leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backLogin) forControlEvents:UIControlEventTouchUpInside];
    [navcBar addSubview:leftButton];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(6);
        make.width.offset(24);
        make.height.offset(22);
        make.bottom.offset(-12);
    }];

    
    [self getxianhuoORderDetail];
    
    
    
    //购物车按钮
    UIButton*rightButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setBackgroundImage:[UIImage imageNamed:@"gouwuche"] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(gouwucar) forControlEvents:UIControlEventTouchUpInside];
    [navcBar addSubview:rightButton];
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15);
        make.width.offset(22);
        make.height.offset(20);
        make.bottom.offset(-15);
    }];

    
    
    
    arrayT=@[
             @"货 品 详 情:",
             @"品           名:",
             @"材 质/表 面:",
             @"规           格:",
             @"数 量/总 重:",
             @"生   产   商:",
             @"边           部:",
             @"等           级:",
             @"包           装:",
             @"交    割    库:",
             @"备           注:"
             ];
    
 //材质表面
    NSString *czbm=[NSString stringWithFormat:@"%@/%@",_Datalist.MaterialCode,_Datalist.SurfaceCode];
//数量总重
    NSString *slzz=[NSString stringWithFormat:@"%@/%.3fkg",_Datalist.Quantity,_Datalist.TotalWeight.floatValue];
//规格
    NSString *gg=[NSString stringWithFormat:@"%@(%.2f)",_Datalist.SpecCode,_Datalist.ReferenceThick.floatValue];
//交割库
    NSString *jgk;
    
    NSString *housename;
    
    if ([TongYong isBlankObjectAndStr:_Datalist.HouseName]) {
       housename = @"";
    }else{
       housename = _Datalist.HouseName;
    }
    
    if ([TongYong isBlankObjectAndStr:_Datalist.CityName]) {
        
      jgk=[NSString stringWithFormat:@"%@",housename];
    }else{
      jgk=[NSString stringWithFormat:@"%@-%@",housename,_Datalist.CityName];
    }
    
    //边部
    NSString *bianbu;
    if ([TongYong isBlankObjectAndStr:_Datalist.EdgeName]) {
        
    bianbu=[NSString stringWithFormat:@""];
        
    }else{
        bianbu=_Datalist.EdgeName;
    
    }
    
    
    //等级
    NSString *dengji;
    if ([TongYong isBlankObjectAndStr:_Datalist.LevelName]) {
        
        dengji=[NSString stringWithFormat:@""];
        
    }else{
        dengji=_Datalist.LevelName;
        
    }
    
    //包装
    NSString *baozhuang;
    if ([TongYong isBlankObjectAndStr:_Datalist.PackageName]) {
        
        baozhuang=[NSString stringWithFormat:@""];
        
    }else{
        baozhuang=_Datalist.PackageName;
        
    }
    
    weighttext=1;
    
    //在数组中添加
    _detailArray=[[NSMutableArray alloc]initWithObjects:@"",_Datalist.CategoryName,czbm,gg,slzz,_Datalist.FactoryName,bianbu,dengji,baozhuang,jgk,_Datalist.Remark,@"",nil];
    
    //创建表格
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, kNavigationBarHeight, self.view.frame.size.width, self.view.frame.size.height-kNavigationBarHeight-45) style:UITableViewStylePlain];
    _tableView.backgroundColor=[UIColor groupTableViewBackgroundColor];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    [self.view addSubview:_tableView];

    
//加入购物车
    addshop=[[UIButton alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-45, self.view.frame.size.width/2, 45)];
    addshop.backgroundColor=[UIColor whiteColor];
    [addshop setTitle:@"加入购物车" forState:UIControlStateNormal];
    [addshop setTitleColor:[UIColor colorWithRed:252.f/255.f green:123.f/255.f blue:96.f/255.f alpha:1] forState:UIControlStateNormal];
    [addshop addTarget:self action:@selector(jionshopAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addshop];
    
 //立即购买
    buybut=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height-45, self.view.frame.size.width/2, 45)];
    buybut.backgroundColor=[UIColor colorWithRed:251.f/255.f green:87.f/255.f blue:60.f/255.f alpha:1];
    [buybut setTitle:@"立即购买" forState:UIControlStateNormal];
    [buybut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buybut addTarget:self action:@selector(buyAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buybut];
    
    
    NSInteger saleMode=[self.Datalist.SaleMode  integerValue];
  
    if(saleMode == 30){
        
        _titleView = [[UIView alloc]init];
        _titleView.frame = CGRectMake(0, 60, self.view.width, 30);
        _titleView.backgroundColor = RGBCOLOR(255, 111, 76);
        [self.view addSubview:_titleView];
        [self.view bringSubviewToFront:_titleView];
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.font = Font(12);
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.textColor = [UIColor whiteColor];
        titleLabel.text = @"定制货品暂不支持APP下单,如需购买请联系客服!";
        CGSize tempSize = [titleLabel boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 30)];
        titleLabel.center = CGPointMake(self.view.width * 0.5, 15);
        titleLabel.bounds = CGRectMake(0, 0, tempSize.width+10, 30);
        [_titleView addSubview:titleLabel];
        
        UIButton *closeButton = [[UIButton alloc] init];
        closeButton.frame = CGRectMake(self.view.frame.size.width-25, 5, 20, 20);
        [closeButton setBackgroundImage:[UIImage imageNamed:@"ic_close_imageviewer"] forState:UIControlStateNormal];
        [closeButton addTarget:self action:@selector(removeTitleView) forControlEvents:UIControlEventTouchUpInside];
        [_titleView addSubview:closeButton];

        addshop.hidden = YES;
        buybut.hidden = YES;
       
        UIButton *zhaohuobutton=[[UIButton alloc]init];
        zhaohuobutton.frame=CGRectMake(40, self.view.frame.size.height-45, self.view.frame.size.width-80, 40);
        [zhaohuobutton.layer setMasksToBounds:YES];
        [zhaohuobutton.layer setCornerRadius:20.0]; //设置矩圆角半径
        zhaohuobutton.backgroundColor=[UIColor whiteColor];
        zhaohuobutton.layer.borderWidth=1;
        zhaohuobutton.layer.borderColor=RGBCOLOR(24, 163, 246).CGColor;
        [zhaohuobutton  setTitleColor:RGBCOLOR(24, 163, 246) forState:UIControlStateNormal];
        [zhaohuobutton addTarget:self action:@selector(zhaohuobuttonAction) forControlEvents:UIControlEventTouchUpInside];
        [zhaohuobutton setTitle:@"试试吆喝找货？" forState:UIControlStateNormal];
        [self.view addSubview:zhaohuobutton];
    }
}

//试试要和找货
-(void)zhaohuobuttonAction{

    AccurateVC*accurate=[[AccurateVC alloc]init];
    accurate.Datalist=self.Datalist;
    
    accurate.typeString=self.Datalist.TopCategoryName;//传过去字符串（判断该以什么样的方式显示）
    accurate.pageString=@"试试吆喝找货";
    [self.navigationController pushViewController:accurate animated:YES];


}

- (void)removeTitleView {
    [_titleView removeFromSuperview];
    _titleView = nil;
}

//请求数据
-(void)getxianhuoORderDetail{

    //获取
    NSMutableDictionary *di=[[NSMutableDictionary alloc]init];
    [di setValue:_Datalist.ProductID forKey:@"product_id"];
    //要判断什么类型的然后穿的参数不同
    
    [Controller requestWithURL:ProductDetail jsondic:di finishBlock:^(ClassData* data) {
        
        if ([data.number isEqualToNumber:[NSNumber numberWithInteger:0]]) {
            
        } else {
            ALERTSHOW(@"该货品已下架");
            
            UILabel *labe=[[UILabel alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-65, self.view.frame.size.width, 20)];
            labe.text=@"已下架";
            labe.backgroundColor=[UIColor colorWithRed:(40/255.0f) green:(40/255.0f) blue:(40/255.0f) alpha:0.6f];
            labe.font=[UIFont systemFontOfSize:13];
            labe.textColor=[UIColor whiteColor];
            labe.textAlignment=NSTextAlignmentCenter;
            [self.view addSubview:labe];
            [self.view bringSubviewToFront:labe];
            
            addshop.alpha=0.5;
            addshop.userInteractionEnabled=NO;
            buybut.alpha=0.5;
            buybut.userInteractionEnabled=NO;
            
            
            
        }
    }];


}

//购物车事件
- (void)gouwucar {
    [MobClick event:@"intoTheShoppingCart"];
    
    NSString *IDnumString=[NSString stringWithFormat:@"%@",_yongHuQuanXuanModel.COMPANY_ID];
    if ([IDnumString isEqualToString:@"0"]) {
        NSString *statusSt=[NSString stringWithFormat:@"%@",_yongHuQuanXuanModel.STATUS];
        if ([TongYong isBlankObjectAndStr:_yongHuQuanXuanModel.STATUS]||[statusSt isEqualToString:@"-1"]) {
            //没有值便是 申请
            //没有绑定公司 （提示是否加入公司  或者  创建公司  或者 输入验证码 加入公司）
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:@"您还没有“创建/加入”一家公司，不能进行该操作"
                                                           delegate:self
                                                  cancelButtonTitle:@"取消"
                                                  otherButtonTitles:@"创建公司",@"查找公司",@"输入邀请码",nil];
            
            //这个属性继承自UIView，当一个视图中有多个AlertView时，可以用这个属性来区分
            alert.tag = 43;
            //只读属性，看AlertView是否可见
            [alert show];
            
        }else{
            //0申请中  -1被拒绝
            
            NSString *messageSt=[NSString stringWithFormat:@"您于%@申请加入“%@”，公司主管理员尚未同意您加入公司。",_yongHuQuanXuanModel.APPLY_TIME,_yongHuQuanXuanModel.APPLY_COMPANY_NAME];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:messageSt
                                                           delegate:self
                                                  cancelButtonTitle:@"取消申请"
                                                  otherButtonTitles:@"关闭",nil];
            
            //这个属性继承自UIView，当一个视图中有多个AlertView时，可以用这个属性来区分
            alert.tag = 100;
            //只读属性，看AlertView是否可见
            [alert show];
            
            
        }
        
    }else{
        
        gouwuCarVC *gwc = [[gouwuCarVC alloc] init];
        [self.navigationController pushViewController:gwc animated:YES];
        
    }

}

//判断是否创建公司
-(void)panduanCreate
{
    [Controller requestWithURL:POSTCHECK jsondic:nil finishBlock:^(ClassData *data) {
        if ([data.number isEqualToNumber:[NSNumber numberWithInteger:0]]){
           _yongHuQuanXuanModel=[YongHuQuanXuanModel mj_objectWithKeyValues:data.data];
        }
    }];
    
    
}

- (void)backLogin {
    [self.navigationController popViewControllerAnimated:YES];
}
//加入购物车
-(void)jionshopAction{
    [MobClick event:@"addToShoppingCart"];
//    weighttext//数量
    
    NSMutableDictionary *di=[[NSMutableDictionary alloc]init];

    NSNumber *weight=[NSNumber numberWithInteger:weighttext];
    
    [di setValue:@"1433739374266387" forKey:@"memberId"];
    [di setValue:_Datalist.ProductID forKey:@"productId"];
    [di setValue:weight forKey:@"quantity"];
    
    [Controller requestWithURL:POSTADDPRODUCT jsondic:di finishBlock:^(ClassData* data) {
        
        if ([data.number isEqualToNumber:[NSNumber numberWithInteger:0]])
        {
          
            ALERTSHOW(@"成功加入购物车！");
            
        }else
        {
            ALERTSHOW(data.message);
           
           
        }
    }];
    

}


//立即购买
-(void)buyAction{
    
    [MobClick event:@"buyNow"];
    
    //先判断是否开通资金账户
    
    [self  isfoundkaitong];

}

-(void)buytosureview
{
    //转换model
    gouwucartModel *mod=[[gouwucartModel alloc]init];
    mod.PRODUCT_ID=_Datalist.ProductID;
    mod.USEABLE_QUANTITY=_Datalist.Quantity;
    mod.REFERENCE_THICK=_Datalist.ReferenceThick;
    mod.SURFACE_CODE=_Datalist.SurfaceCode;
    mod.QUANTITY=[NSString stringWithFormat:@"%ld",(long)weighttext];
    mod.MANUFACTURER_NAME=_Datalist.FactoryName;
    mod.SHAPE=@"";
    mod.SPEC_CODE=_Datalist.SpecCode;
    mod.CATEGORY_NAME=_Datalist.CategoryName;
    mod.EDGE_NAME=_Datalist.EdgeName;
    mod.PARENT_NAME=_Datalist.TopCategoryName;
    mod.LEVEL_NAME=_Datalist.LevelName;
    
    if ([_Datalist.PackageName isEqualToString:@"正常包装"]) {
        mod.PACKAGE_TYPE=@"0";
    }else if([_Datalist.PackageName isEqualToString:@"简包"]){
        mod.PACKAGE_TYPE=@"10";
        
    }else if([_Datalist.PackageName isEqualToString:@"精包"]){
        mod.PACKAGE_TYPE=@"20";
    }else {
        //        if([_Datalist.PackageName isEqualToString:@"裸包"])
        mod.PACKAGE_TYPE=@"30";
        
    }
    mod.HOUSE_NAME=_Datalist.HouseName;
    mod.PRICE_UNIT=_Datalist.PriceUnit;
    mod.DISCOUNT_PRICE=_Datalist.Price;
    mod.USEABLE_WEIGHT=_Datalist.UnitWeight;
    mod.MATERIAL_CODE=_Datalist.MaterialCode;
    mod.SALES_PROMOTION=_Datalist.IsPreferential;
    mod.UnitWeight=_Datalist.UnitWeight;
    mod.TotalWeight=_Datalist.TotalWeight;
    
    SureOrderVC *surevc=[[SureOrderVC alloc]init];
    surevc.gouwuMDT=mod;
    surevc.isXianhuo=@"现货列表";
    [self.navigationController pushViewController:surevc animated:YES];
    
    


}

-(void)isfoundkaitong
{
    
    //先判断是否开通资金账户
    [Controller requestWithURL:ISFOUND jsondic:nil finishBlock:^(ClassData* data) {
        
        if ([data.number isEqualToNumber:[NSNumber numberWithInteger:0]])
        {
            
            //            "is_bind" = 1;
            //            "is_found" = 1;
            //            "is_main" = 1;
            //            "main_mobile" = 0;
            //            "main_name" = "";
            
            
            //            "main_mobile":0,               只有当前账号绑定公司 并且不是主账号的时候 此字段才有手机号  默认为0
            //            "is_bind":1,                       1已绑定   0未绑定
            //            "is_main":0,                      1主账号   0子账号
            //            "main_name":"",
            //            "is_found":1                     1已开通   0未开通
            
            //是否开通
            NSString *is_found=[NSString  stringWithFormat:@"%@",data.data[@"is_found"]];
            NSInteger is_fd=is_found.integerValue;
            
            //是否是 主账号，子账号
            NSString *is_main=[NSString  stringWithFormat:@"%@",data.data[@"is_main"]];
            NSInteger is_ma=is_main.integerValue;
            //是否绑定
            NSString *is_bind=[NSString  stringWithFormat:@"%@",data.data[@"is_bind"]];
            NSInteger is_b=is_bind.integerValue;
            
            
            iphoneNum=data.data[@"main_mobile"];
            
            if (is_fd==1) {
                //已开通  资金账户（进入确认订单页面）
                
                [self buytosureview];

                
            }else{
                //未开通
                //先判断是否开通     没开通的时候 判断是否有公司   然后再判断主子账号
                
                if (is_b==1) {
                    //绑定了公司  提示其开通资金账户
                    if (is_ma==1) {
                        //主账号
                        //初始化AlertView
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                        message:@"贵公司还没有开通资金账户！"
                                                                       delegate:self
                                                              cancelButtonTitle:@"开通资金账户"
                                                              otherButtonTitles:nil,nil];
                        alert.tag = 40;
                        [alert show];
                        
                    }else{
                        //子账号
                        //初始化AlertView
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                        message:[NSString stringWithFormat:@"贵公司还没有开通资金账户！\n请联系主账号，登录信用行网站或吆喝APP开通资金账户。\n主账号：%@  %@",data.data[@"main_name"],iphoneNum]
                                                                       delegate:self
                                                              cancelButtonTitle:@"取消"
                                                              otherButtonTitles:@"呼叫客服",@"呼叫主账号",nil];
                        alert.tag = 41;
                        [alert show];
                        
                    }
                    
                }else{
                    //未绑定公司  提示去绑定公司
                    NSString *statusSt=[NSString stringWithFormat:@"%@",_yongHuQuanXuanModel.STATUS];
                    if ([TongYong isBlankObjectAndStr:_yongHuQuanXuanModel.STATUS]||[statusSt isEqualToString:@"-1"]) {
                        //没有值便是 申请
                        //没有绑定公司 （提示是否加入公司  或者  创建公司  或者 输入验证码 加入公司）
                        
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                        message:@"您还没有“创建/加入”一家公司，不能进行该操作"
                                                                       delegate:self
                                                              cancelButtonTitle:@"取消"
                                                              otherButtonTitles:@"创建公司",@"查找公司",@"输入邀请码",nil];
                        
                        //这个属性继承自UIView，当一个视图中有多个AlertView时，可以用这个属性来区分
                        alert.tag = 43;
                        //只读属性，看AlertView是否可见
                        [alert show];
                        
                    }else{
                        //0申请中
                        NSString *messageSt=[NSString stringWithFormat:@"您于%@申请加入“%@”，公司主管理员尚未同意您加入公司。",_yongHuQuanXuanModel.APPLY_TIME,_yongHuQuanXuanModel.APPLY_COMPANY_NAME];
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                                        message:messageSt
                                                                       delegate:self
                                                              cancelButtonTitle:@"取消申请"
                                                              otherButtonTitles:@"关闭",nil];
                        
                        //这个属性继承自UIView，当一个视图中有多个AlertView时，可以用这个属性来区分
                        alert.tag = 100;
                        //只读属性，看AlertView是否可见
                        [alert show];
                        
                        
                    }

                }
                
            }
            
        }else
        {
            ALERTSHOW(data.message);
            
            
        }
    }];
    
    
    
}

//根据被点击按钮的索引处理点击事件
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (alertView.tag==40) {
        if (buttonIndex==0) {
            //开通资金账户
            zijinzhanghuVC*zijinVC=[[zijinzhanghuVC alloc]init];
            [self.navigationController pushViewController:zijinVC animated:YES];
            
        }
        
    }else if(alertView.tag==41){
        
        if (buttonIndex==1) {
            //呼叫客服
            
            //进入打电话页面
            UIWebView *webview = [[UIWebView alloc] init];
            [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:4008850054"]]];
            [self.view addSubview:webview];
            
            
            
        }else if(buttonIndex==2){
            //呼叫主账号
            
            //进入打电话页面
            UIWebView *webview = [[UIWebView alloc] init];
            NSString *str=[NSString stringWithFormat:@"tel:%@",iphoneNum];
            [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
            [self.view addSubview:webview];
            
            
            
        }if (buttonIndex==0) {
            //取消
            
            
        }
        
    }if (alertView.tag==43) {
        if(buttonIndex==0){
            //取消
        }else if (buttonIndex==1) {
            //创建公司
            CreateCompanyVC*creatVC=[CreateCompanyVC new];
            [self.navigationController pushViewController:creatVC animated:YES];
            
        }else if(buttonIndex==2){
            //查找公司
            FindCompanyViewController*findCompanyViewController=[FindCompanyViewController new];
            [self.navigationController pushViewController:findCompanyViewController animated:NO];
            
        }else if (buttonIndex==3){
            //输入邀请码
            CompanyInviteCodeViewController *companyInviteCodeViewController=[CompanyInviteCodeViewController new];
            [self.navigationController pushViewController:companyInviteCodeViewController animated:YES];
        }
        
    }else if(alertView.tag==100){
        if (buttonIndex==0) {
            //取消申请
            [self quxiaoshenqingBut];
        }else{
        
        }
        
    }
}
//取消加入公司申请
-(void)quxiaoshenqingBut{
    
    [Controller requestWithURL:PostCancelApply jsondic:nil finishBlock:^(ClassData *data) {
        if ([data.number isEqualToNumber:[NSNumber numberWithInteger:0]]){
            ALERTSHOW(@"你已成功取消加入该公司的申请")
        }else{
            
            ALERTSHOW(data.message);
        }
    }];
    
}

//返回单元格的分区个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
//返回单元格的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   
    return 14;
    
}
//返回每个单元格要显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //没有下方的报价
    
    
        UITableViewCell*cell=[[UITableViewCell alloc]init];
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        //第0行
        UILabel*nameLabel=[[UILabel alloc]init];
        nameLabel.font=font15;
        [cell addSubview:nameLabel];
        if (indexPath.row==0)
        {
            //求购详情label
            nameLabel.frame=CGRectMake(20, 5, 150, 25);
            nameLabel.text=arrayT[indexPath.row];
            //显示价格
            UILabel*creatTime=[[UILabel alloc]init];
            //拼接价格
            NSString *priceUnit;
            
            NSInteger prt=[self.Datalist.PriceUnit integerValue];
            if (prt==10) {
                
                priceUnit=@"元/吨";
            }else if (prt==20) {
                
                priceUnit=@"元/支";
            }else if (prt==30) {
                
                priceUnit=@"元/千克";
            }else if (prt==40) {
                
                priceUnit=@"元/张";
            }
            NSString *price=[NSString stringWithFormat:@"￥%@%@", self.Datalist.Price, priceUnit];
            creatTime.text=price;
            creatTime.font=font15;
            creatTime.textAlignment=NSTextAlignmentRight;
            creatTime.textColor=[UIColor colorWithRed:251.f/255.f green:96.f/255.f blue:70.f/255.f alpha:1];
            creatTime.frame=CGRectMake(150, 5, self.view.frame.size.width-170, 25);
            [cell addSubview:creatTime];
            
            //分割线
            UIImageView *fenge=[[UIImageView alloc]initWithFrame:CGRectMake(0, cell.frame.size.height-10, self.view.frame.size.width, 6)];
            UIImage *image=[UIImage imageNamed:@"ic_fengexian"];
            // 设置左边端盖宽度
            NSInteger leftCapWidth = image.size.width * 0.95;
            // 设置上边端盖高度
            NSInteger topCapHeight = image.size.height * 0.5;
            
            UIImage *newImage = [image stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
            
            fenge.image=newImage;
            
            [cell addSubview:fenge];
            
            
        }else if (indexPath.row==1)
        {
            //求购详情label
            nameLabel.frame=CGRectMake(20, 5, 150, 25);
            nameLabel.textColor=Color153;
            nameLabel.text=arrayT[indexPath.row];
            //显示详细信息
            UILabel*messageL=[[UILabel alloc]initWithFrame:CGRectMake(120, 12, self.view.frame.size.width-125, 16)];
            messageL.text=_detailArray[indexPath.row];
            messageL.textColor=Color153;
            messageL.font=font15;
            messageL.numberOfLines=0;
            [cell addSubview:messageL];
            
            
//            UIButton *dianhu=[[UIButton alloc]init];
//            dianhu.layer.borderWidth=1;
//            dianhu.layer.borderColor=[UIColor colorWithRed:21.f/255.f green:164.f/255.f blue:249.f/255.f alpha:1].CGColor;
//            // 设置圆角半径
//            dianhu.layer.masksToBounds = YES;
//            dianhu.layer.cornerRadius = 4;
//
//            [dianhu setTitleEdgeInsets:UIEdgeInsetsMake(5,8, 5, 5)];
//            [dianhu setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
//            dianhu.titleLabel.font=[UIFont systemFontOfSize:11];
//            [dianhu setTitle:@"呼叫卖家" forState:UIControlStateNormal];
//            [dianhu setTitleColor:[UIColor colorWithRed:21.f/255.f green:164.f/255.f blue:249.f/255.f alpha:1] forState:UIControlStateNormal];
//            [dianhu setImage:[UIImage imageNamed:@"ic_call_saler"] forState:UIControlStateNormal];
//            [dianhu addTarget:self action:@selector(callto) forControlEvents:UIControlEventTouchUpInside];
//            dianhu.frame=CGRectMake(self.view.frame.size.width-100, 5, 80, 25);
//            [cell addSubview:dianhu];

            
            

        
        }else if (indexPath.row==11) {
            //灰色底部
            cell.backgroundColor=[UIColor colorWithRed:247.f/255.f green:247.f/255.f blue:247.f/255.f alpha:1];
            
            UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(0, -1, self.view.frame.size.width+10, 2)];
            lab.text=@" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
            lab.textColor=[UIColor colorWithRed:204.f/255.f green:204.f/255.f blue:204.f/255.f alpha:1];
//            lab.backgroundColor=[UIColor whiteColor];
            [cell addSubview:lab];
            
           NSArray *arraybac=@[
                     @"提供发票",
                     @"加工服务",
                     @"质量证书（质量保障）",
                     @"运输服务（运费与卖家协商）",
                     ];
            
            NSInteger jianju=20;
            CGRect txtFrame;
            UILabel *caizhi;
            UIImageView*xuanHuoImg;
            for (NSInteger i=0; i<arraybac.count; i++) {
                caizhi=[[UILabel alloc]init];
                [cell addSubview:caizhi];
                caizhi.text=arraybac[i];
                caizhi.backgroundColor=[UIColor clearColor];
                caizhi.font=[UIFont systemFontOfSize:11];
                caizhi.textAlignment=NSTextAlignmentCenter;
                caizhi.numberOfLines = 0;
                //对勾
                xuanHuoImg=[[UIImageView alloc]init];
                xuanHuoImg.image=[UIImage imageNamed:@"Free_to_find_goods"];
                [cell addSubview:xuanHuoImg];

                
                //自适应高度
                NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12],};
                CGSize textSize = [arraybac[i] boundingRectWithSize:CGSizeMake(200, 200) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;;
                if(i==0){
                    caizhi.frame=CGRectMake(jianju+17, 5+(5+15)*(i/3), textSize.width+6, 15);
                    xuanHuoImg.frame=CGRectMake(jianju, 5+(5+15)*(i/3), 15, 15);
                    
                }else if(i/3==1){
                    
                    caizhi.frame=CGRectMake(jianju+17, 5+(5+15)*(i/3), textSize.width+6, 15);
                    xuanHuoImg.frame=CGRectMake(jianju, 5+(5+15)*(i/3), 15, 15);
                    
                }else{
                    
                    CGSize textSize1 = [arraybac[i-1] boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
                    caizhi.frame=CGRectMake(txtFrame.origin.x+jianju+textSize1.width+17, 5+(5+15)*(i/3), textSize.width+6, 15);
                    
                    xuanHuoImg.frame=CGRectMake(txtFrame.origin.x+jianju+textSize1.width, 5+(5+15)*(i/3), 15, 15);;
                
                }
                
                txtFrame=caizhi.frame;
                
            }
        } else if (indexPath.row == 12) {
        
            UIView *viewCel = [[UIView alloc]initWithFrame:CGRectMake(0, 10, self.view.frame.size.width, 60)];
            viewCel.backgroundColor=[UIColor whiteColor];
            [cell addSubview:viewCel];
            cell.backgroundColor=[UIColor clearColor];
            
            UILabel* yixuanLabel = [[UILabel alloc] init];
            yixuanLabel.font = Font(15);
            yixuanLabel.text = @"已        选:";
            yixuanLabel.frame = CGRectMake(10, 25, 70, 20);
            yixuanLabel.textColor = Color153;
            [viewCel addSubview:yixuanLabel];
            
            //减号按钮
            Redbut = [[UIButton alloc] init];
            Redbut.layer.borderWidth = 1;
            Redbut.layer.borderColor = [UIColor colorWithRed:204.f/255.f green:204.f/255.f blue:204.f/255.f alpha:1].CGColor;
            Redbut.titleLabel.font = [UIFont systemFontOfSize:15];
            [Redbut setTitle:@"-" forState:UIControlStateNormal];
            [Redbut setTitleColor:Color153 forState:UIControlStateNormal];
            [Redbut addTarget:self action:@selector(RedButton:) forControlEvents:UIControlEventTouchUpInside];
            Redbut.frame = CGRectMake(yixuanLabel.right+20, 25, 25, 25);
            [viewCel addSubview:Redbut];
            
            //中间重量显示
            zhongliang = [[UITextField alloc] initWithFrame:CGRectMake(Redbut.right, 25, 110, 25)];
            zhongliang.layer.borderWidth = 1;
            zhongliang.layer.borderColor = [UIColor colorWithRed:204.f/255.f green:204.f/255.f blue:204.f/255.f alpha:1].CGColor;
            zhongliang.textAlignment = NSTextAlignmentCenter;
            zhongliang.text = [NSString stringWithFormat:@"%ld",(long)weighttext];
            zhongliang.delegate = self;
            [zhongliang addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
            [viewCel addSubview:zhongliang];
            
            //加号按钮
            Addbut = [[UIButton alloc] init];
            Addbut.layer.borderWidth = 1;
            Addbut.layer.borderColor = [UIColor colorWithRed:204.f/255.f green:204.f/255.f blue:204.f/255.f alpha:1].CGColor;
            Addbut.titleLabel.font = [UIFont systemFontOfSize:15];
            [Addbut setTitle:@"+" forState:UIControlStateNormal];
            [Addbut setTitleColor:Color153 forState:UIControlStateNormal];
            [Addbut addTarget:self action:@selector(addButton:) forControlEvents:UIControlEventTouchUpInside];
            Addbut.frame = CGRectMake(zhongliang.right, 25, 25, 25);
            [viewCel addSubview:Addbut];
            
            //单位
            danwei = [[UILabel alloc] init];
            danwei.frame = CGRectMake(Addbut.right+2, 30, 70, 16);
            [viewCel addSubview:danwei];
            
            // 提示图标和提示文字
            UIImageView *tipImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tishi.png"]];
            tipImageView.frame = CGRectMake(Redbut.left, 7, 15, 15);
            tipImageView.hidden = YES;
            [viewCel addSubview:tipImageView];
            
            UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(tipImageView.right+10, 7, 130, 15)];
            tipLabel.font = Font(11);
            tipLabel.textColor = [UIColor lightGrayColor];
            tipLabel.text = @"平板重量以理论计算为准";
            tipLabel.hidden = YES;
            [viewCel addSubview:tipLabel];
            
            //判断库存
            NSString *dan;
            if ([_Datalist.TopCategoryName isEqualToString:@"卷"]||[_Datalist.TopCategoryName isEqualToString:@"卷材"]||[_Datalist.TopCategoryName isEqualToString:@"带"]||[_Datalist.TopCategoryName isEqualToString:@"带材"]) {
                
                    dan=@"个";
                    danwei.text=dan;
                    danwei.font=[UIFont systemFontOfSize:15];
                    danwei.textColor=Color153;
                
            }else if([_Datalist.TopCategoryName isEqualToString:@"板"]||[_Datalist.TopCategoryName isEqualToString:@"板材"]){
                if (_Datalist.Quantity.integerValue<10) {
                    
                    danwei.text=@"库存紧张";
                    danwei.font=[UIFont systemFontOfSize:11];
                    danwei.textColor=[UIColor colorWithRed:251.f/255.f green:96.f/255.f blue:70.f/255.f alpha:1];
                }else{
                    dan=@"张";
                    danwei.text=dan;
                    danwei.font=[UIFont systemFontOfSize:15];
                    danwei.textColor=Color153;
                }
                
                // 只要板材展示就可以了，其他类型不用展示
                tipImageView.hidden = NO;
                tipLabel.hidden = NO;
                
            }else if([_Datalist.TopCategoryName isEqualToString:@"管"]||[_Datalist.TopCategoryName isEqualToString:@"管材"]){
                if (_Datalist.Quantity.integerValue<10) {
                    
                    danwei.text=@"库存紧张";
                    danwei.font=[UIFont systemFontOfSize:11];
                    danwei.textColor=[UIColor colorWithRed:251.f/255.f green:96.f/255.f blue:70.f/255.f alpha:1];
                }else{
                    dan=@"支";
                    danwei.text=dan;
                    danwei.font=[UIFont systemFontOfSize:15];
                    danwei.textColor=Color153;
                }
            }else if([_Datalist.TopCategoryName isEqualToString:@"型"]||[_Datalist.TopCategoryName isEqualToString:@"型材"]){
                if (_Datalist.Quantity.integerValue<10) {
                    
                    danwei.text=@"库存紧张";
                    danwei.font=[UIFont systemFontOfSize:11];
                    danwei.textColor=[UIColor colorWithRed:251.f/255.f green:96.f/255.f blue:70.f/255.f alpha:1];
                }else{
                    dan=@"个";
                    danwei.text=dan;
                    danwei.font=[UIFont systemFontOfSize:15];
                    danwei.textColor=Color153;
                }
            }

            //判断加号是否可用
            if (weighttext >= _Datalist.Quantity.integerValue) {
                Addbut.backgroundColor=[UIColor colorWithRed:242.f/255.f green:242.f/255.f blue:242.f/255.f alpha:1];
                Addbut.userInteractionEnabled=NO;
            }
            //判断减号是否可用
            if (weighttext <= 1) {
                Redbut.backgroundColor = [UIColor colorWithRed:242.f/255.f green:242.f/255.f blue:242.f/255.f alpha:1];
                Redbut.userInteractionEnabled=NO;
            }
            
            
            
            NSInteger saleMode=[self.Datalist.SaleMode  integerValue];
           
            if (saleMode == 30) {
                
                cell.hidden=YES;
                
            }

            
            
        } else if (indexPath.row == 13) {
            // 虚线
            cell.backgroundColor=[UIColor colorWithRed:247.f/255.f green:247.f/255.f blue:247.f/255.f alpha:1];
            UILabel *lab=[[UILabel alloc] initWithFrame:CGRectMake(0, -1, self.view.frame.size.width+10, 2)];
            lab.text = @" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
            lab.textColor = [UIColor colorWithRed:204.f/255.f green:204.f/255.f blue:204.f/255.f alpha:1];
            [cell addSubview:lab];
            
            // 电话找货按钮
            UIButton*phoneBtnz=[UIButton buttonWithType:UIButtonTypeCustom];
            phoneBtnz.layer.masksToBounds=YES;
            phoneBtnz.layer.cornerRadius=18;
            [phoneBtnz setBackgroundImage:[UIImage imageNamed:@"fujiaokefu"] forState:UIControlStateNormal];
            [phoneBtnz setBackgroundImage:[UIImage imageNamed:@"hujiaokefu_hl"] forState:UIControlStateHighlighted];
            [phoneBtnz addTarget:self action:@selector(callPhoneBut) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:phoneBtnz];
            phoneBtnz.frame=CGRectMake(20, 5, 50, 50);
            
            // 单价
            UILabel *danjiaLabel = [[UILabel alloc] init];
            danjiaLabel.textAlignment = NSTextAlignmentCenter;
            danjiaLabel.numberOfLines = 1;
            danjiaLabel.font = Font(10);
            self.danjiaLabel = danjiaLabel;
            
            // 合计
            UILabel *hejiLabel = [[UILabel alloc] init];
            hejiLabel.textAlignment = NSTextAlignmentCenter;
            hejiLabel.numberOfLines = 1;
            hejiLabel.font = Font(10);
            self.hejiLabel = hejiLabel;
            
            // 计算合计总价方法
            [self calculateTheTotalPrice];
            
            CGSize tempDanjiaLabelSize = [danjiaLabel boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20)];
            danjiaLabel.frame = CGRectMake(self.view.frame.size.width-tempDanjiaLabelSize.width-40, 4, tempDanjiaLabelSize.width+20, 20);
            [cell addSubview:danjiaLabel];
            
            CGSize tempHejiLabelSize = [hejiLabel boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 20)];
            hejiLabel.frame = CGRectMake(self.view.frame.size.width-tempHejiLabelSize.width-40, 30, tempHejiLabelSize.width+20, 20);
            [cell addSubview:hejiLabel];
            
            
            NSInteger saleMode=[self.Datalist.SaleMode  integerValue];
           
            if (saleMode == 30) {
                
//                cell.hidden=YES;

                lab.hidden = YES;
                danjiaLabel.hidden = YES;
                hejiLabel.hidden = YES;
                cell.backgroundColor = [UIColor clearColor];
            }

            
            
        } else {
            //其他行
            //商品详情
            nameLabel.text = arrayT[indexPath.row];
            nameLabel.font = Font(15);
            nameLabel.frame = CGRectMake(20, 12.5, 100, 16);
            nameLabel.textColor = Color153;
            
            //显示详细信息
            UILabel* messageL = [[UILabel alloc] initWithFrame:CGRectMake(120, 12.5, self.view.frame.size.width-nameLabel.right, 16)];
            messageL.text = _detailArray[indexPath.row];
            messageL.textColor = Color153;
            messageL.font = Font(15);
            messageL.numberOfLines = 0;
            
            if (indexPath.row == 10) {
                messageL.frame = CGRectMake(120, 12.5, self.view.frame.size.width-140, [_detailArray[indexPath.row] boundingRectWithSize: CGSizeMake(messageL.frame.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:messageL.font ,NSFontAttributeName, nil] context:nil].size.height);
            }
            [cell addSubview:messageL];
        }
    
        return cell;
    
}


- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [UIView animateWithDuration:0.25 animations:^{
        self.view.frame=CGRectMake(0, -200, self.view.frame.size.width, self.view.frame.size.height);
    }];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    
    UITableViewCell * cell = (UITableViewCell *)[[textField superview] superview];
    NSIndexPath *indexPath = [_tableView indexPathForCell:cell];
    
    if (textField.text.length == 0 || [textField.text intValue] == 0) {
        textField.text = @"1";
        weighttext = 1;
    }
    
    //如果输入框内容大于最大值则等于最大值
    if (weighttext > _Datalist.Quantity.integerValue) {
        textField.text = [NSString stringWithFormat:@"%@", _Datalist.Quantity];
        weighttext = _Datalist.Quantity.integerValue;
    }
    
    [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    
    // 计算合计总价方法
    [self calculateTheTotalPrice];
    
    [UIView animateWithDuration:0.25 animations:^{
        self.view.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }];
}


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

{  //string就是此时输入的那个字符 textField就是此时正在输入的那个输入框 返回YES就是可以改变输入框的值 NO相反
    
    
    
    if ([string isEqualToString:@"\n"])  //yes  按会车可以改变
        
    {
        
        return YES;
        
    }
    
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容
    
    weighttext=toBeString.integerValue;
    
      return [self validateNumber:string];
    
    return YES;
}

//只能输入数字的判断
- (BOOL)validateNumber:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}


//键盘弹下
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)disMiss {
    return;
}

//打电话按钮
- (void)callPhoneBut {
    //进入打电话页面
    UIWebView *webview = [[UIWebView alloc] init];
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:4008850051"]]];
    [self.view addSubview:webview];
}

//加号按钮事件
- (void)addButton:(id)sender {
    
    
    [MobClick event:@"increasePurchases"];
    
    UITableViewCell * cell = (UITableViewCell *)[[sender superview] superview];
    NSIndexPath * path = [_tableView indexPathForCell:cell];
    //加号按钮
    weighttext++;

    if (weighttext>=_Datalist.Quantity.integerValue) {
        
        weighttext=_Datalist.Quantity.integerValue;
        
//        Addbut.backgroundColor=[UIColor colorWithRed:242.f/255.f green:242.f/255.f blue:242.f/255.f alpha:1];
//        Addbut.userInteractionEnabled=NO;
    }

    zhongliang.text = [NSString stringWithFormat:@"%ld",(long)weighttext];
    
    // 计算合计总价方法
    [self calculateTheTotalPrice];
    
    
    [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:path,nil] withRowAnimation:UITableViewRowAnimationNone];
}

//减号按钮事件
- (void)RedButton:(id)sender {
    
    [MobClick event:@"minusPurchase"];
    
    UITableViewCell * cell = (UITableViewCell *)[[sender superview] superview];
    NSIndexPath * path = [_tableView indexPathForCell:cell];
    
    //减号按钮
    weighttext--;
    if (weighttext<=1) {
        weighttext=1;
//        Redbut.backgroundColor=[UIColor colorWithRed:242.f/255.f green:242.f/255.f blue:242.f/255.f alpha:1];
//        Redbut.userInteractionEnabled=NO;
    }
    zhongliang.text=[NSString stringWithFormat:@"%ld",(long)weighttext];
    
    // 计算合计总价方法
    [self calculateTheTotalPrice];
    
    [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:path,nil] withRowAnimation:UITableViewRowAnimationNone];
}

//返回每个单元格的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row==0)
    {
        return 40;
    }
    
    if (indexPath.row==10)
    {
            return [self stringRect:_Datalist.Remark uiWidth:140 font:[UIFont systemFontOfSize:15]]+18;
    }

    if (indexPath.row==11)
    {
        return 45;
    }
    if (indexPath.row==12)
    {
        return 70;
    }
    if (indexPath.row==13)
    {
        return 60;
    }

    return 30;
    
    
}
#pragma mark--------------其他方法
//计算文字高度
-(NSInteger)stringRect:(NSString*)str uiWidth:(NSInteger)widt font:(UIFont*)lfont
{
    //CGRect rect=[str boundingRectWithSize:CGSizeMake(widt, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:lfont ,NSFontAttributeName, nil] context:nil].size.height;
    //MAXFLOAT
    CGRect rect = [str boundingRectWithSize:CGSizeMake(self.view.frame.size.width-widt, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:[[NSDictionary alloc] initWithObjectsAndKeys:lfont,NSFontAttributeName, nil] context:nil];
    return rect.size.height;
}

#pragma mark - 计算合计总价的方法
- (void)calculateTheTotalPrice {
    // 计算合计总价
    NSInteger prt = [self.Datalist.PriceUnit integerValue];
    NSString *priceUnit;
    if (prt == 10) {
        priceUnit = @"(元/吨)";
        
        NSString *weightString = [NSString cutOutZeroToEndWithString:[NSString stringWithFormat:@"%f", _Datalist.UnitWeight.doubleValue/1000 * weighttext]];
        NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"单价:%@%@ X 总量:%@吨", _Datalist.Price, priceUnit, weightString]];
        NSString *priceString = [NSString stringWithFormat:@"%@", _Datalist.Price];
        [tempString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(3, priceString.length)];
        [tempString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(14+priceString.length, weightString.length)];
        self.danjiaLabel.attributedText = tempString;
        
        NSDecimalNumber *danjiaNumber = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%@", _Datalist.Price]];
        NSDecimalNumber *zhongliangNumber = [[NSDecimalNumber alloc] initWithDouble:_Datalist.UnitWeight.doubleValue/1000 * weighttext];
        NSDecimalNumber *price = [danjiaNumber decimalNumberByMultiplyingBy:zhongliangNumber];
        NSString *tempPriceString = [NSString notRounding:price afterPoint:2];
        NSMutableAttributedString *tempTotalString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"合计:%@(元)", tempPriceString]];
        [tempTotalString addAttribute:NSForegroundColorAttributeName
                                value:[UIColor redColor]
                                range:NSMakeRange(3, tempPriceString.length)];
        self.hejiLabel.attributedText = tempTotalString;
    } else if (prt == 20) {
        priceUnit = @"(元/支)";
        
        NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"单价:%@%@ X 总量:%ld支", _Datalist.Price, priceUnit, (long)weighttext]];
        NSString *priceString = [NSString stringWithFormat:@"%@", _Datalist.Price];
        NSString *amountString = [NSString stringWithFormat:@"%ld", (long)weighttext];
        [tempString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(3, priceString.length)];
        [tempString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(14+priceString.length, amountString.length)];
        self.danjiaLabel.attributedText = tempString;
        
        NSDecimalNumber *danjiaNumber = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%@", _Datalist.Price]];
        NSDecimalNumber *zhongliangNumber = [[NSDecimalNumber alloc] initWithInteger: weighttext];
        NSDecimalNumber *price = [danjiaNumber decimalNumberByMultiplyingBy:zhongliangNumber];
        NSString *tempPriceString = [NSString notRounding:price afterPoint:2];
        NSMutableAttributedString *tempTotalString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"合计:%@(元)", tempPriceString]];
        [tempTotalString addAttribute:NSForegroundColorAttributeName
                                value:[UIColor redColor]
                                range:NSMakeRange(3, tempPriceString.length)];
        self.hejiLabel.attributedText = tempTotalString;
    } else if (prt == 30) {
        priceUnit = @"(元/千克)";
        
        NSString *weightString = [NSString cutOutZeroToEndWithString:[NSString stringWithFormat:@"%f", _Datalist.UnitWeight.doubleValue * weighttext]];
        NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"单价:%@%@ X 总量:%@千克", _Datalist.Price, priceUnit, weightString]];
        NSString *priceString = [NSString stringWithFormat:@"%@", _Datalist.Price];
        [tempString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(3, priceString.length)];
        [tempString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(15+priceString.length, weightString.length)];
        self.danjiaLabel.attributedText = tempString;
        
        NSDecimalNumber *danjiaNumber = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%@", _Datalist.Price]];
        NSDecimalNumber *zhongliangNumber = [[NSDecimalNumber alloc] initWithDouble:_Datalist.UnitWeight.doubleValue * weighttext];
        NSDecimalNumber *price = [danjiaNumber decimalNumberByMultiplyingBy:zhongliangNumber];
        NSString *tempPriceString = [NSString notRounding:price afterPoint:2];
        NSMutableAttributedString *tempTotalString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"合计:%@(元)", tempPriceString]];
        [tempTotalString addAttribute:NSForegroundColorAttributeName
                                value:[UIColor redColor]
                                range:NSMakeRange(3, tempPriceString.length)];
        self.hejiLabel.attributedText = tempTotalString;
    } else if (prt == 40) {
        priceUnit = @"(元/张)";
        
        NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"单价:%@%@ X 总量:%ld张", _Datalist.Price, priceUnit, (long)weighttext]];
        NSString *priceString = [NSString stringWithFormat:@"%@", _Datalist.Price];
        NSString *amountString = [NSString stringWithFormat:@"%ld", (long)weighttext];
        [tempString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(3, priceString.length)];
        [tempString addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(14+priceString.length, amountString.length)];
        self.danjiaLabel.attributedText = tempString;
        
        NSDecimalNumber *danjiaNumber = [[NSDecimalNumber alloc] initWithString:[NSString stringWithFormat:@"%@", _Datalist.Price]];
        NSDecimalNumber *zhongliangNumber = [[NSDecimalNumber alloc] initWithInteger: weighttext];
        NSDecimalNumber *price = [danjiaNumber decimalNumberByMultiplyingBy:zhongliangNumber];
        NSString *tempPriceString = [NSString notRounding:price afterPoint:2];
        NSMutableAttributedString *tempTotalString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"合计:%@(元)", tempPriceString]];
        [tempTotalString addAttribute:NSForegroundColorAttributeName
                                value:[UIColor redColor]
                                range:NSMakeRange(3, tempPriceString.length)];
        self.hejiLabel.attributedText = tempTotalString;
    }
}

@end
